/*
 * @(#)SharedCollectionPanel.java
 * 
 * Copyright(C) 2004 Yujin Kim
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.netexplode.jtunes.client.ui.component;

import java.awt.Color;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cdavies.itunes.Track;

import com.netexplode.jtunes.model.media.SharedCollection;

/**
 * <code>LocalCollectionPanel</code> represents .....
 * 
 * @author ykim
 * @version $Revision: 1.2 $
 * @since 0.1
 */
public class SharedCollectionPanel extends CollectionPanel {

	private static final long serialVersionUID = 1L;

	private final static Log log = LogFactory.getLog(SharedCollectionPanel.class);

	public void init() {
		log.info("init");

		tables = new JTable[collectionManager.getSharedCollections().size()];

		for (int i = 0; i < tables.length; i++) {
			log.info("adding collection " + i);
			final SharedCollection collection = (SharedCollection) collectionManager.getSharedCollections().get(i);
			// final int size = collection.size();
			final Track[] tracks = collection.getTracks();

			final Object[][] data = new Object[tracks.length][columnNames.length];
			for (int j = 1; j < tracks.length; j++) {
				log.info("adding " + j + " | " + tracks[j].getArtistName());
				data[j][0] = tracks[j].getArtistName();
				data[j][1] = tracks[j].getAlbumName();
				data[j][2] = tracks[j].getTrackName();
				collectionLoaded = true;
			}

			tables[i] = new JTable(new DefaultTableModel(data, columnNames) {
				/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

				public boolean isCellEditable(int row, int column) {
					return false;
				}
			});

			tables[i].setShowGrid(true);
			tables[i].setGridColor(Color.BLACK);
			tables[i].setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

			this.addEventLister(tables[i]);

			super.add(getTable());
			collectionLoaded = true;

		}
	}

	protected JTable getTable() {
		return this.tables[collectionManager.getSharedPosition()];
	}

}